package com.kehutong.applet.service.impl;

import com.kehutong.applet.entity.AdvertPositionEntity;
import com.kehutong.applet.entity.AppletMenuPageEntity;
import com.kehutong.applet.service.AdvertPositionService;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.orm.Pool;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.orm.jdbc.Page;
import org.coraframework.orm.jdbc.execute.entity.FindPage;

import java.util.List;

/**
 * @program: kht
 * @description:
 * @author: joneron
 * @create: 2021/5/24
 **/
public class AdvertPositionServiceImpl implements AdvertPositionService {

    private static final Logger logger = LoggerFactory.getLogger(AdvertPositionServiceImpl.class);

    @Inject
    private JdbcSession jdbcSession;

    @Override
    public Page<AdvertPositionEntity> findPage(JSONObject jsonObject) {

        FindPage<AdvertPositionEntity> find = jdbcSession.findPage(AdvertPositionEntity.class)
                .eq("deleted", false)
                .eq(jsonObject,"status")
                .like(jsonObject,"positionName")
                .order("createTime", "desc");

        find.page(jsonObject);

        return find.exe();
    }

    @Override
    public List<AdvertPositionEntity> findList(JSONObject jsonObject) {
        List<AdvertPositionEntity> advertList = jdbcSession.findArray(AdvertPositionEntity.class)
                .eq("deleted", false)
                .eq("status",true)
                .exe();

        return advertList;
    }

    @Override
    public Integer save(AdvertPositionEntity advertPositionEntity) {
        return jdbcSession.insert(advertPositionEntity);
    }

    @Override
    public Integer update(AdvertPositionEntity advertPositionEntity) {
        return jdbcSession.updateById(advertPositionEntity);
    }

    @Override
    public Integer deleteById(String id) {
        AdvertPositionEntity result = Pool.get(AdvertPositionEntity.class, id);
        if (result != null) {
            result.setDeleted(true);
            jdbcSession.updateById(result);
        }
        return 1;
    }
}
